/*************************************************************************
 *
 *  Copyright (C) 2013 Florian Dang <florian.coin@gmail.com>
 *
 *  This file is part of NatusVerse.
 *
 *  NatusVerse is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  NatusVerse is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with NatusVerse.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

#ifndef INC_GRAPHICS_GRAPHICS_H_
#define INC_GRAPHICS_GRAPHICS_H_

/*!
 * \file        graphics.h
 * \brief       SDL graphic window header file
 * \author      Florian Dang
 * \date        2013
 */

#include <cmath>
#include <SDL.h>


#include "graphics/color.h"
#include "utils.h"

namespace graphics
{

//! Graphics class
/*!
  This class defines the SDL graphical window
*/
class Graphics
{
	public:
		typedef struct s_point
		{
			float x;
			float y;
		} t_point;

		typedef struct s_vector
		{
			float x;
			float y;
		} t_vector;

		static const t_point  kpoint_orig_t;
		static const t_vector kforce_orig_t;

		//! Default constructor
		Graphics(int w = default_width, int h = default_height)
			: w_(w), h_(h), autoprint_(false),
			  show_cursor_(false), mousepos_(kpoint_orig_t)
			{
				SDL_Init(SDL_INIT_VIDEO);
				SDL_screen_ = SDL_SetVideoMode(w_, h_, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
			}
		//! Alternative constructor taking automatic display argument
		Graphics(int w, int h, bool autoprint, bool cursor)
			: w_(w), h_(h), autoprint_(autoprint),
			  show_cursor_(cursor), mousepos_(kpoint_orig_t)
			{
				SDL_Init(SDL_INIT_VIDEO);
				SDL_screen_ = SDL_SetVideoMode(w_, h_, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
			}

		//! Destructor
		~Graphics() {}

		//! Width accessor
		int  GetW() const { return w_; }
		//! Height accessor
		int  GetH() const { return h_; }
		//! Autoprint bool accessor
		bool GetAutoprint() const {return autoprint_;}

		void    InitGraphics();
		void    PrintScreen();
		void    FillScreen(color::t_color color);
		void    AddPix(int x, int y, color::t_color color);
		void    PrintImg(char *filename, t_point bg, int w, int h);
		t_point WaitClic();
		void    WaitEscape();
		void    Quit();
		
		static float Distance(t_point p1, t_point p2)
		{
			float d;

			d = (p1.x - p2.x) * (p1.x - p2.x) + \
				(p1.y - p2.y) * (p1.y - p2.y);

			return (sqrtf(d));
		}

	private:
		int                 w_;
		int                 h_;
		bool                autoprint_;
		bool				show_cursor_;
		SDL_Surface         *SDL_screen_;
		t_point             mousepos_;
};
} // end namespace



#endif  // INC_GRAPHICS_GRAPHICS_H_

